//
//  ZCVideoView.m
//  BaiSi
//
//  Created by 张灿 on 16/5/4.
//  Copyright © 2016年 张灿. All rights reserved.
//

#import "ZCVideoView.h"
#import <UIImageView+WebCache.h>
#import <MediaPlayer/MediaPlayer.h>

@interface ZCVideoView ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@property (weak, nonatomic) IBOutlet UILabel *playCount;

@property (weak, nonatomic) IBOutlet UILabel *playTime;

@end

@implementation ZCVideoView

- (void)setItem:(ZCThemeItem *)item
{
    [super setItem:item];
    
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:item.image0]];
    
    self.playCount.text = [NSString stringWithFormat:@"%@播放", item.playcount];
    
    //设置时间
    NSString *time = [NSString stringWithFormat:@"%02ld:%02ld", item.videotime.integerValue / 60, item.videotime.integerValue % 60];
    self.playTime.text = time;
}

- (IBAction)playVideoClick:(id)sender {
    NSURL *url = [NSURL URLWithString:self.item.videouri];
    //创建视频播放控制器
    MPMoviePlayerViewController *vc = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
    
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:vc animated:YES completion:nil];
}


@end
